package com.itwk.gulimall.product.controller;

import com.itwk.common.utils.PageUtils;
import com.itwk.common.utils.R;
import com.itwk.gulimall.product.entity.PmsSpuInfoEntity;
import com.itwk.gulimall.product.service.PmsSpuInfoService;
import com.itwk.gulimall.product.vo.SaveSpuVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * spu信息
 *
 * @author wangke
 * @email wangke19970512@163.com
 * @date 2021-01-07 23:03:03
 */
@RestController
@RequestMapping("product/spuinfo")
public class PmsSpuInfoController {
    @Autowired
    private PmsSpuInfoService pmsSpuInfoService;

    /*
    *  /product/spuinfo/save
    * 商品提交保存接口，通过此接口接收所有的商品参数，再调用各个服务接口保存
    * */
    @PostMapping("/save")
     public R saveSpuInfo(@RequestBody SaveSpuVo spuVo){
        pmsSpuInfoService.saveSpuVo(spuVo);
        return R.ok();
    }

    /*
    *
    * /product/spuinfo/{spuId}/up
    *  商品上架，将需要检索的属性保存并传输到search微服务，保存到es中
    * */
    @PostMapping("/{spuId}/up")
    public R spuUp(@PathVariable Long spuId){
        pmsSpuInfoService.spuUp(spuId);
        return R.ok();
    }
    /**
     * 列表
     */
    @RequestMapping("/list")
  //  @RequiresPermissions("product:pmsspuinfo:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = pmsSpuInfoService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
  //  @RequiresPermissions("product:pmsspuinfo:info")
    public R info(@PathVariable("id") Long id){
		PmsSpuInfoEntity pmsSpuInfo = pmsSpuInfoService.getById(id);

        return R.ok().put("pmsSpuInfo", pmsSpuInfo);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
  //  @RequiresPermissions("product:pmsspuinfo:update")
    public R update(@RequestBody PmsSpuInfoEntity pmsSpuInfo){
		pmsSpuInfoService.updateById(pmsSpuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
   // @RequiresPermissions("product:pmsspuinfo:delete")
    public R delete(@RequestBody Long[] ids){
		pmsSpuInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
